import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    const token = ref('')
    const user = ref({})
    // 设置个人信息
    const setUser = ({ username, password }) => {
      user.value.username = username
      user.value.password = password
    }

    // 清除个人信息
    const removeUser = () => {
      user.value = {}
    }
    // 设置token
    const setToken = ({ token: newToken }) => {
      token.value = newToken
    }
    // 清除token
    const removeToken = () => {
      token.value = null
    }
    return {
      token,
      user,
      setToken,
      removeToken,
      removeUser,
      setUser,
    }
  },
  {
    persist: true,
  },
)
